package com.goods.controller.business;

import com.goods.business.service.SupplierService;
import com.goods.common.model.business.Supplier;
import com.goods.common.response.ResponseBean;
import com.goods.common.vo.business.SupplierVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "业务管理-物资来源相关接口")
@RequestMapping("/business/supplier")
@RestController
public class SupplierController {
    @Autowired
    private SupplierService supplierService;
    @GetMapping("/findAll")
    public ResponseBean findAll(){
        List<Supplier> suppliers =  supplierService.findAll();
        return ResponseBean.success(suppliers);
    }
    //分页展示入库数据
    @GetMapping("/findSupplierList")
    public ResponseBean showSupplier(@RequestParam Map pageMap) {
        Map result = supplierService.showSupplier(pageMap);
        return ResponseBean.success(result);
    }

    //添加
    @PostMapping("/add")
    public ResponseBean addSupplier(@RequestBody SupplierVO supplierVO) {
        supplierService.addSupplier(supplierVO);
        return ResponseBean.success();
    }

    //编辑弹窗回显
    @GetMapping("/edit/{id}")
    public ResponseBean showEdit(@PathVariable Long id) {
        SupplierVO supplierVO = supplierService.showEdit(id);
        return ResponseBean.success(supplierVO);
    }

    //编辑
    @PutMapping("/update/{id}")
    public ResponseBean update(@PathVariable Long id,@RequestBody SupplierVO supplierVO) {
        supplierService.updateSupplier(id,supplierVO);
        return ResponseBean.success();
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteSupplier(@PathVariable Long id) {
        supplierService.deleteSupplier(id);
        return ResponseBean.success();
    }
}
